package com.fw.ui.view.settings.usercontrol.bouser.event;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fw.ui.view.event.AbstractValueChangeListener;
import com.fw.ui.view.settings.usercontrol.bouser.EditBOUserView;
import com.vaadin.data.Property.ValueChangeEvent;

@Component
@Scope(SCOPE_PROTOTYPE)
public class EditBOUserEmployeeIdValueChangeListener extends AbstractValueChangeListener {

    private static final long serialVersionUID = 1L;

    @Override
    public boolean validate(ValueChangeEvent event) throws Exception {
	EditBOUserView editBOUserView = (EditBOUserView) this.getBasedComponent();
	editBOUserView.getRow4Validate().setVisible(false);
	editBOUserView.getLblEmployeeIdValidateMessage().setValue("");
	editBOUserView.getTxtEmployeeId().removeStyleName("v-textfield-error");
	boolean employeeIdValid = editBOUserView.getTxtEmployeeId().isValid();
	if (!employeeIdValid) {
	    editBOUserView.getTxtEmployeeId().addStyleName("v-textfield-error");
	    if (editBOUserView.getTxtEmployeeId().getErrorMessage() != null) {
		editBOUserView.getLblEmployeeIdValidateMessage().setValue(
			editBOUserView.getTxtEmployeeId().getErrorMessage().getFormattedHtmlMessage());
	    }
	    editBOUserView.getRow4Validate().setVisible(true);
	}
	return true;
    }

    @Override
    public void change(ValueChangeEvent event) throws Exception {
	// TODO Auto-generated method stub

    }

}
